﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using Microsoft.Phone.Storage;
using System.Windows.Navigation;

namespace TestPhone
{

    public abstract class SelectObject : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
        private string m_Title;

        public string Title
        {
            get { return m_Title; }
            set
            {
                m_Title = value;
                NotifyPropertyChanged("Title");
            }
        }

        public abstract Uri Image { get; }

        public virtual bool CanDelete { get { return false; } }

    }
    public class FileObject : SelectObject
    {
        public override Uri Image
        {
            get { return new Uri("036.png", UriKind.RelativeOrAbsolute); }
        }
        public string Filename { get; set; }
        public override bool CanDelete
        {
            get
            {
                return true;
            }
        }
    }

    public class FolderObject : SelectObject
    {
        public override Uri Image
        {
            get { return new Uri("folder.png", UriKind.RelativeOrAbsolute); }
        }
        public string Folder { get; set; }
    }

    public class ExternalFileObject : SelectObject
    {
        public override Uri Image
        {
            get { return new Uri("036.png", UriKind.RelativeOrAbsolute); }
        }
        public ExternalStorageFile File { get; set; }
    }
    public class ExternalFolderObject : SelectObject
    {
        public override Uri Image
        {
            get { return new Uri("folder.png", UriKind.RelativeOrAbsolute); }
        }
        public ExternalStorageFolder Folder { get; set; }

    }
    public class BackToMainObject : SelectObject
    {
        public override Uri Image
        {
            get { return null; }
        }
        public IList<SelectObject> BackList { get; set; }

    }

    class CustomURIMapper : UriMapperBase
    {
        private string tempUri;

        public override Uri MapUri(Uri uri)
        {
            tempUri = uri.ToString();

            // File association launch
            // Example launch URI: /FileTypeAssociation?fileToken=89819279-4fe0-4531-9f57-d633f0949a19
            if (tempUri.Contains("/FileTypeAssociation"))
            {
                // Get the file ID (after "fileToken=").
                int fileIDIndex = tempUri.IndexOf("fileToken=") + 10;
                string fileID = tempUri.Substring(fileIDIndex);

                // Map the file association launch to route page.
                return new Uri("/MainPage.xaml?fileToken=" + fileID, UriKind.Relative);
            }

            // Otherwise perform normal launch.
            return uri;
        }
    }

}
